package com.jiangnan.service.Impl;

import com.jiangnan.mapper.DeptMapper;
import com.jiangnan.pojo.Dept;
import com.jiangnan.service.DeptService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

@Service
public class DeptServiceImpl implements DeptService {

    @Autowired
    private DeptMapper deptMapper;

    @Override
    public List<Dept> findAll() {
        List<Dept> deptList = deptMapper.findAll();
        return deptList;
    }

    @Override
    public void deleteById(Integer id) {
        deptMapper.deleteById(id);
    }

    @Override
    public void addDept(Dept dept) {
        // 1. 补全基础属性
        dept.setCreateTime(LocalDateTime.now());
        dept.setUpdateTime(LocalDateTime.now());
        // 2. 执行插入
        deptMapper.insertDept(dept);
    }

    @Override
    public Dept getById(Integer id) {
        Dept dept = deptMapper.getById(id);
        return dept;
    }

    @Override
    public void updateDept(Dept dept) {
        // 1. 补全基础属性
        dept.setUpdateTime(LocalDateTime.now());
        // 2. 执行更新
        deptMapper.updateDept(dept);
    }
}
